package imper.graphic;

import imper.graphic.event.ClickEvent;

import java.util.ArrayList;
import java.util.List;

public class Button implements Clickable
{
	protected int _X1;
	protected int _Y1;
	protected int _X2;
	protected int _Y2;
	protected List<ButtonListener> _listener;

	public Button(int pX, int pY, int pW, int pH)
	{
		this._X1 = pX;
		this._Y1 = pY;
		this._X2 = pX + pW;
		this._Y2 = pY + pH;
		_listener = new ArrayList<ButtonListener>();
	}
	
	protected boolean isInZone( int pX,int pY)
	{
		return _X1 < pX && pX < _X2 && _Y1 < pY && pY < _Y2;
	}
	
	public void click( int pX,int pY)
	{
		if( isInZone( pX,pY))
		{	
			ClickEvent event = new ClickEvent(this);
			for( ButtonListener listener : _listener )
			{
				listener.click(event);
			}
		}
	}
	
	public void addListener( ButtonListener pListener)
	{
		_listener.add(pListener);
	}
}
